﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using WoChu.Autorun.Base.Dao;
using WoChu.Autorun.Base.Model;
using MB.Orm.Common;
using System.Web;
using Newtonsoft.Json;
using Model;
using WoChu.Autorun.Logic;

namespace WebApi.Controllers
{
    public class WCS_TO_WMSController : ApiController
    {
        //[HttpGet]
        //public ResultModel getWCS_TO_WMSlist(string BoxNO)
        //{
        //    MB.Util.TraceEx.Write(BoxNO);
        //    WCS_TO_WMSBase dao = new WCS_TO_WMSBase();

        //    ResultModel res = dao.getWCS_TO_WMSlist(BoxNO);

        //    return res;
        //}

        //[HttpPost]
        //public ResultModel SendWMStoWCStask(int DetailNO, string OrderNO, int UserID, string UserName, string FboxNO)
        //{
        //    WCS_TO_WMSBase dao = new WCS_TO_WMSBase();
        //    List<string> lstFboxNO = new List<string>();
        //    try
        //    {
        //        lstFboxNO = JsonConvert.DeserializeObject<List<string>>(FboxNO);
        //    }
        //    catch
        //    {
        //        return new ResultModel { RESULT = "failed", MESSAGE = "泡沫箱号无法解析", DATA = null };
        //    }

        //    ResultModel res = dao.Sendtask(DetailNO, OrderNO, UserID, UserName, lstFboxNO);

        //    return res;
        //}
        //[HttpPost]
        //public ResultModel SendReCheckExcep(int DeatilNO, string OrderNO, int UserID, string UserName, int excepType, string boxNO)
        //{
        //    WCS_TO_WMSBase dao = new WCS_TO_WMSBase();

        //    ResultModel res = dao.SendReCheckExcep(DeatilNO, OrderNO, UserID, UserName, excepType, boxNO);

        //    return res;
        //}

        [HttpPost]
        public ResultModel SendWMStoWCStask(WMStoWCStask model)
        {

            WCS_TO_WMSBase dao = new WCS_TO_WMSBase();
            if(model.FBOXS.Count<=0)
            { 
                return new ResultModel { RESULT = "failed", MESSAGE = "泡沫箱号无法解析", DATA = null };
            }

            ResultModel res = dao.Sendtask(model.DETAILNO, model.ORDERNO, model.USERID, model.USERNAME, model.CHECK_LOCATION, model.FBOXS);

            return res;
        }

        [HttpGet]
        public ResultModel checkWMS_TO_WCStask(string OrderNO)
        {

            WCS_TO_WMSBase dao = new WCS_TO_WMSBase();
            if (string.IsNullOrEmpty(OrderNO))
            {
                return new ResultModel { RESULT = "failed", MESSAGE = "订单号为空", DATA = null };
            }

            ResultModel res = dao.checkWMS_TO_WCStask(OrderNO);

            return res;
        } 

        [HttpPost]
        public ResultModel UpdateWMS_TO_WCSTASKfboxs(string OrderNO, int UserID, string UserName, List<string> FboxNO)
        {
            WCS_TO_WMSBase dao = new WCS_TO_WMSBase();
            if (string.IsNullOrEmpty(OrderNO))
            {
                return new ResultModel { RESULT = "failed", MESSAGE = "订单号为空", DATA = null };
            }
            if (string.IsNullOrEmpty(UserID.ToString()))
            {
                return new ResultModel { RESULT = "failed", MESSAGE = "用户ID为空，请重新登录", DATA = null };
            }
            if (string.IsNullOrEmpty(UserName))
            {
                return new ResultModel { RESULT = "failed", MESSAGE = "用户名为空，请重新登录", DATA = null };
            }
            if (FboxNO==null || FboxNO.Count<=0)
            {
                return new ResultModel { RESULT = "failed", MESSAGE = "发货箱为空", DATA = null };
            }

            ResultModel res = dao.UpdateWMS_TO_WCSTASKfboxs(OrderNO, UserID, UserName, FboxNO);

            return res;
        }

        [HttpPost]
        public ResultModel DebindFBOX(string BoxNO, int UserID, string UserName)
        {
            WCS_TO_WMSBase dao = new WCS_TO_WMSBase();

            ResultModel res = dao.DebindBoxNO(BoxNO, UserID, UserName);

            return res;
        }


        #region 手机APP接口

        [HttpGet]
        public ResultModel GetAPPPickOrderInfoByOrderNO(string OrderNO, int UserID, string UserName ,int flag = 0)
        {
            WCS_TO_WMSBase dao = new WCS_TO_WMSBase();
            return dao.GetPickOrderInfoByOrderNO(OrderNO, UserID, UserName, flag);
        }

        [HttpPost]
        public ResultModel AppSaveWMStoWCStask(List<WMS_APP_PICK_ORDER> list)
        {
            WCS_TO_WMSBase dao = new WCS_TO_WMSBase();
            return dao.SaveWMS_APP_PICK_ORDER(list);
        }

        [HttpPost]
        public ResultModel AppSendWMStoWCStask(WMStoWCStask taskModel)
        {
            WCS_TO_WMSBase dao = new WCS_TO_WMSBase();
            return dao.SendWMStoWCStaskByApp(taskModel);
        }

        [HttpGet]
        public ResultModel GetUserAppPickInfo(int UserId,int Flag=0)
        {
            WCS_TO_WMSBase dao = new WCS_TO_WMSBase();
            return dao.GetPickOrderInfoByUserID(UserId, Flag);
        }
        #endregion
    }
}
